package com.mariusz.utils;

import static org.junit.Assert.*;

import java.util.Calendar;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import com.mariusz.data.dto.Payment;
import com.mariusz.data.dto.Rentier;
import com.mariusz.data.enums.PaymentsIntervals;

public class PaymentsCalculatorTest {
	private Rentier rentier;
	private PaymentsCalculator calc;
	@Before
	public void setup(){ 
		rentier = new Rentier();
		rentier.setName("The Name");
		rentier.setDepositAmount(1.0);
		rentier.setPaymentAmount(50.00);
		rentier.setDocument("000000");
		rentier.setTelephone("0700");
		rentier.setPaymentInterval(PaymentsIntervals.WEEKLY);
		calc = new PaymentsCalculator(); 
	}
	
	@Test
	public void testLessThanAWeek() {
		Calendar cal = Calendar.getInstance();
		cal.set(2011, 4, 1);
		rentier.setContractBeginDate(cal.getTime());
		cal.set(2011,4,6);
		rentier.setContractEndDate(cal.getTime());
		
		List<Payment> payments = calc.calculate(rentier);
		
		assertNotNull(payments);
		assertTrue("Paymenst count: "+payments.size(),payments.size() == 1);
	}
	@Test
	public void testExaclyAWeek() {
		Calendar cal = Calendar.getInstance();
		cal.set(2011, 4, 1);
		rentier.setContractBeginDate(cal.getTime());
		cal.set(2011,4,8);
		rentier.setContractEndDate(cal.getTime());
		
		List<Payment> payments = calc.calculate(rentier);
		
		assertNotNull(payments);
		assertTrue("Paymenst count: "+payments.size(),payments.size() == 1);
	}
	
	@Test
	public void testMoreThanAWeek() {
		Calendar cal = Calendar.getInstance();
		cal.set(2011, 4, 1);
		rentier.setContractBeginDate(cal.getTime());
		cal.set(2011,4,9);
		rentier.setContractEndDate(cal.getTime());
		
		List<Payment> payments = calc.calculate(rentier);
		
		assertNotNull(payments);
		assertTrue("Paymenst count: "+payments.size(),payments.size() != 1);
	}
	
	@Test
	public void testLessThanAMonth(){
		Calendar cal = Calendar.getInstance();
		cal.set(2011, 4, 1);
		rentier.setContractBeginDate(cal.getTime());
		cal.set(2011,4,31);
		rentier.setContractEndDate(cal.getTime());
		rentier.setPaymentInterval(PaymentsIntervals.MONTHLY);
		
		List<Payment> payments = calc.calculate(rentier);
		
		assertNotNull(payments);
		assertTrue("Paymenst count: "+payments.size(),payments.size() == 1);
	}
}
